package com.shou.types.common.rediskey;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * ClassName:TokenContext
 * Project:yvt-rule
 * Package: com.sunlight.types.context
 * Description
 *
 * @Author xuyi
 * @Create 2024/12/3 11:12
 * @Version 1.0
 */
public class TokenContext {

    static ThreadLocal<BaseUserInfo> threadLocal = new InheritableThreadLocal<>();

    private TokenContext() {}

    public static void setBaseUserInfo(BaseUserInfo baseUserInfo) {
        threadLocal.set(baseUserInfo);
    }

    public static BaseUserInfo getBaseUserInfo() {
        return threadLocal.get();
    }

    public static void removeBaseUserInfo() {
        threadLocal.remove();
    }

    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    @Builder
    public static class BaseUserInfo {
        Long userId;
        String userName;
    }
}
